package com.anhuanjia.tools.eao.util;

import com.efastsoft.framework.data.DataRow;
import com.efastsoft.framework.data.DataTable;
import com.efastsoft.framework.data.Q;
import com.efastsoft.framework.utility.StringUtil;

public class GBTUtil {

	/**
	 * 获取GBT名字
	 * 
	 * @param value
	 * @return
	 */
	public static String getname(String value) {
		// String s = "[\"A\",\"1A\",\"11A\",\"119A\"]";
		if (!StringUtil.isEmpty(value)) {
			String[] st = value.split("\"");
			if (st.length == 3) {
				DataTable dt = new Q("select TypeName from eao_gbt where Stype = ?", st[1]).fetch();
				String laber = null;
				for (DataRow dr : dt) {
					laber = dr.getString(0);
				}
				return laber;
			} else if (st.length == 5) {
				DataTable dt = new Q("select TypeName from eao_gbt where Stype = ?", st[3]).fetch();
				String laber = null;
				for (DataRow dr : dt) {
					laber = dr.getString(0);
				}
				return laber;
			} else if (st.length == 7) {
				DataTable dt = new Q("select TypeName from eao_gbt where Stype = ?", st[5]).fetch();
				String laber = null;
				for (DataRow dr : dt) {
					laber = dr.getString(0);
				}
				return laber;
			} else if (st.length == 9) {
				DataTable dt = new Q("select TypeName from eao_gbt where Stype = ?", st[7]).fetch();
				String laber = null;
				for (DataRow dr : dt) {
					laber = dr.getString(0);
				}
				return laber;
			} else {
				return "未识别";
			}
		}
		return null;

	}

	/**
	 * 获取管理名录
	 * 
	 * @param value
	 * @return
	 */
	public static String getManagement(String value) {
		if (!StringUtil.isEmpty(value)) {
			String st[] = value.split("\"");
			if (st.length == 3) {
				DataTable dt = new Q("select Type from eao_management where Mid = ?", st[1]).fetch();
				String laber = null;
				for (DataRow dr : dt) {
					laber = dr.getString(0);
				}
				return laber;
			} else if (st.length == 5) {
				DataTable dt = new Q("select Type from eao_management where Father = ? AND Mid = ?", st[1], st[3])
						.fetch();
				String laber = null;
				for (DataRow dr : dt) {
					laber = dr.getString(0);
				}
				return laber;
			} else {
				return "未识别";
			}
		}
		return null;
	}
	/*
	 * public static void main(String[] args) { String bs= "[\"106\"]"; String b=
	 * GBTUtil.getManagement(bs); System.out.println(b);
	 * 
	 * }
	 */
}
